<?php
/**
 * Project: HTPHouDuan
 * User: xilibo
 * Date: 2018/2/5 0005
 */

namespace app\admin\api;

use app\common\controller\CommonController;

class GameApi extends CommonController
{
    /**
     * 获取会员下注量日志统计
     */
    public function betLog($param = [])
    {
        $condition = [];
        if (isset($param['page'])) $condition['page'] = intval($param['page']);
        if (isset($param['siteid'])) $condition['site_id'] = intval($param['siteid']);
        if (isset($param['userid'])) $condition['user_id'] = intval($param['userid']);
        if (isset($param['gameid'])) $condition['game_id'] = intval($param['gameid']);
        $gameBetModel = model('game_bet');
        $field = 'u.*, g.*, gb.*';

        try {
            $result = $gameBetModel->getList(['where'=> $condition]);
            if (!empty($result) && isset($condition['user_id'])){
                try {
                    $userModel = new UserBetModel();
                    $userModel->save(['bet_count' => count($result)], ['user_id' => $condition['user_id']]);
                } catch (Exception $e){
                    return $this->jsonError('更新用户下注量出错，请重试 ' . $e->getMessage());
                }
            }

            return $result;
        } catch (Exception $e){
            return $this->jsonError('查询出错 ' . $e->getMessage());
        }

    }

}